<!-- 展示票务信息 -->
<template>
	<view class="colStart">
		<unicloud-db ref="udb" v-slot:default="{data, loading, error, options}" :options="options"
			collection="ndp-theater-order" orderby="createDate desc" :where="where">
			<view v-if="error" class="error">{{error.message}}</view>
			<view v-else class="list">
				<uni-list v-if="data.length > 0" clickable>
					<uni-list-item :border="false" clickable v-for="(item,index) in data" @click="onJumpDetail(item)"
						:key="index">
						<template v-slot:body>
							<div class="rowStart" style="width: 100%;">
								<image :src="item.coverImg" style="width: 100px;height: 120px;border-radius: 8px;"
									mode="aspectFill">
								</image>
								<div style="margin-left: 16px;flex:1" class="colAround">
									<div style="font-size: 16px;font-weight: 500;color:#353535">{{item.productName}}
									</div>
									<div style="font-size: 16px;font-weight: 400;color: #333333;margin-bottom: 6px;margin-top: 10px;">
										{{item.theaterSession}}
									</div>
									<div class="rowBetween" >
										<div style="color: #353535;font-size: 16px;">支付金额: <span
												style="font-weight: bold;color: #f04e7c;">￥{{ (item.totalMoney / 100).toFixed(2)}}</span>
										</div>	
										<div style="font-size: 14px;">数量 x{{item.tickerNum}}</div>
									</div>
									<div v-if="item.isInvalid" class="row" style="color: #f04e7c;font-size: 16px;padding: 2px 0;">订单已取消</div>
								</div>
							</div>
						</template>
					</uni-list-item>
				</uni-list>
				<view v-else style="width: 100%;line-height: 60px;background-color: white;text-align: center;">暂无数据
				</view>
			</view>
			<view v-if="loading" class="loading">加载中...</view>
		</unicloud-db>
	</view>
</template>

<script lang="ts" setup>
	import { computed, nextTick, onMounted, ref, watch } from "vue"
	import { onLoad, onReachBottom, onPullDownRefresh } from "@dcloudio/uni-app"
	import { useStore } from "vuex"
	import StrUtil from "@/utils/StrUtils.js"
	import { gzhShare } from "@/utils/WxGzhUtil"
	
	const store = useStore();

	const udb = ref()
	const options = ref({})
	// const where = ref(`isInvalid==false && isDeleted == false`)
	const where = computed(() => {
		// if (!StrUtil.isEmpty(store.getters.getUserInfo) && 
		// 	!StrUtil.isEmpty(store.getters.getUserInfo._id)) {
		// 	return `isInvalid==false && isDeleted == false && userId == '${store.getters.getUserInfo._id}'`;
		// } else {
		// 	return `isInvalid==false && isDeleted == false && userId == ''`;
		// }
		if (!StrUtil.isEmpty(store.getters.getUserInfo) &&
			!StrUtil.isEmpty(store.getters.getUserInfo._id)) {
			return `isDeleted == false && userId == '${store.getters.getUserInfo._id}'`;
		} else {
			return `isDeleted == false && userId == ''`;
		}
	});
	
	onLoad(async(option) => {
		console.log("option", option);
		
		gzhShare({
			isShowMenu: false, // 隐藏菜单
			shareInfo: {}
		});
	});

	onMounted(() => {
	})

	onReachBottom(() => {
		try {
			if (!StrUtil.isEmpty(udb.value)) {
				udb.value.loadMore()
			}
		} catch (ex) {
			console.error(ex)
		}
	})

	onPullDownRefresh(() => {
		try {
			// setTimeout(() => {
			if (!StrUtil.isEmpty(udb.value)) {
				// udb.value.refresh()
				// uni.stopPullDownRefresh()
				udb.value.loadData({ clear: true }, () => {
					uni.stopPullDownRefresh()
				})
			}
			// }, 100)
		} catch (err) {
			console.error(err)
		}
	})
	const onJumpDetail = (item : any) => {
		uni.navigateTo({
			url: "/pages/my/orderDetail?id=" + item._id
		})
	}
</script>

<style scoped>
	.cBoard {
		box-shadow: 0px 0px 3px 1px rgba(0, 0, 0, 0.08);
		border-radius: 6px;
		margin: 10px;
		width: calc(100% - 20px);
		padding-bottom: 15px;
	}

	.container {
		width: 100vw;
		height: 100vh;
		display: flex;
		flex-direction: column;
		flex-wrap: nowrap;
		justify-content: flex-start;
		align-items: flex-start;
		align-content: flex-start;
	}

	.scroll-panel {
		overflow: hidden;
		flex: 1;
		width: 100%;
	}

	.cImage {
		width: 100%;
		height: 189px;
		border-top-left-radius: 15px;
		border-top-right-radius: 15px;
	}

	.cSearchFix {
		background-color: white;
		position: fixed;
		height: 100px;
		left: 0;
		right: 0;
		top: 0;
		z-index: 3;
	}

	.cItem {
		width: 100%;
		background-color: white;
	}

	.cWord {
		z-index: 1;
		color: #353535;
		font-size: 16px;
		font-weight: 500px;
		line-height: 32px;
		align-self: flex-start;
		text-align: left;
	}
</style>